home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / C++ / DirectInput / DIConfig / cd3dsurf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-09-27  |  3.8 KB  |  171 lines

  1. #include "common.hpp"
  2. #include "id3dsurf.h"
  3.  
  4. class CDirect3DSurface9: public IDirect3DSurface9Clone
  5. {
  6. public:
  7.     CDirect3DSurface9();
  8.     ~CDirect3DSurface9();
  9. /*    ULONG AddRef();
  10.     HRESULT QueryInterface(REFIID iid, void **ppvObject);
  11.     ULONG Release();*/
  12.  
  13.     // IUnknown methods
  14.     STDMETHOD(QueryInterface) (REFIID  riid, 
  15.                                                          VOID  **ppvObj);
  16.     STDMETHOD_(ULONG,AddRef) ();
  17.     STDMETHOD_(ULONG,Release) ();
  18.  
  19.     // IBuffer methods
  20.     STDMETHOD(SetPrivateData)(REFGUID riid, 
  21.                                                         CONST VOID   *pvData, 
  22.                                                         DWORD   cbData, 
  23.                                                         DWORD   dwFlags);
  24.  
  25.     STDMETHOD(GetPrivateData)(REFGUID riid, 
  26.                                                         VOID   *pvData, 
  27.                                                         DWORD  *pcbData);
  28.  
  29.     STDMETHOD(FreePrivateData)(REFGUID riid);
  30.  
  31.     STDMETHOD(GetContainer)(REFIID riid, 
  32.                                                     void **ppContainer);
  33.  
  34.     STDMETHOD(GetDevice)(IDirect3DDevice9 **ppDevice);
  35.  
  36.     // IDirect3DSurface9 methods
  37.     STDMETHOD_(D3DSURFACE_DESC, GetDesc)();
  38.  
  39.     STDMETHOD(LockRect)(D3DLOCKED_RECT  *pLockedRectData, 
  40.                                             CONST RECT      *pRect, 
  41.                                             DWORD            dwFlags);
  42.  
  43.     STDMETHOD(UnlockRect)();
  44.  
  45.     BOOL Create(int iWidth, int iHeight);
  46.  
  47. /*    HRESULT GetDevice(IDirect3DDevice9** ppDevice);
  48.     HRESULT SetPrivateData(REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
  49.     HRESULT GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData);
  50.     HRESULT FreePrivateData(REFGUID refguid);
  51.     HRESULT GetContainer(REFIID riid, void** ppContainer);
  52.  
  53.     D3DSURFACE_DESC GetDesc();
  54.     HRESULT LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
  55.     HRESULT UnlockRect();*/
  56.  
  57. private:
  58.     int m_iRefCount;
  59.     BYTE *m_pData;
  60.     D3DSURFACE_DESC m_Desc;
  61. };
  62.  
  63. CDirect3DSurface9::CDirect3DSurface9() : m_pData(NULL), m_iRefCount(1)
  64. {
  65. }
  66.  
  67. CDirect3DSurface9::~CDirect3DSurface9()
  68. {
  69.     delete[] m_pData;
  70. }
  71.  
  72. BOOL CDirect3DSurface9::Create(int iWidth, int iHeight)
  73. {
  74.     m_pData = new BYTE[iWidth * iHeight * 4];
  75.     if (!m_pData) return FALSE;
  76.  
  77.     m_Desc.Format = D3DFMT_A8R8G8B8;
  78.     m_Desc.Type = D3DRTYPE_SURFACE;
  79.     m_Desc.Usage = 0;
  80.     m_Desc.Pool = D3DPOOL_SYSTEMMEM;
  81.     m_Desc.Width = iWidth;
  82.     m_Desc.Height = iHeight;
  83.     m_Desc.MultiSampleType = D3DMULTISAMPLE_NONE;
  84.     m_Desc.Width = iWidth;
  85.     m_Desc.Height = iHeight;
  86.     return TRUE;
  87. }
  88.  
  89. STDMETHODIMP_(ULONG) CDirect3DSurface9::AddRef()
  90. {
  91.     return ++m_iRefCount;
  92. }
  93.  
  94. STDMETHODIMP CDirect3DSurface9::QueryInterface(REFIID iid, void **ppvObject)
  95. {
  96.     return E_NOINTERFACE;
  97. }
  98.  
  99. STDMETHODIMP_(ULONG) CDirect3DSurface9::Release()
  100. {
  101.     if (!--m_iRefCount)
  102.     {
  103.         delete this;
  104.         return 0;
  105.     }
  106.     return m_iRefCount;
  107. }
  108.  
  109. /////////// Dummy implementations ///////////////
  110.  
  111. STDMETHODIMP CDirect3DSurface9::SetPrivateData(REFGUID riid, CONST VOID *pvData, DWORD cbData, DWORD dwFlags)
  112. {
  113.     return S_OK;
  114. }
  115.  
  116. STDMETHODIMP CDirect3DSurface9::GetPrivateData(REFGUID riid, VOID *pvData, DWORD *pcbData)
  117. {
  118.     return S_OK;
  119. }
  120.  
  121. STDMETHODIMP CDirect3DSurface9::FreePrivateData(REFGUID riid)
  122. {
  123.     return S_OK;
  124. }
  125.  
  126. STDMETHODIMP CDirect3DSurface9::GetContainer(REFIID riid, void **ppContainer)
  127. {
  128.     return S_OK;
  129. }
  130.  
  131. STDMETHODIMP CDirect3DSurface9::GetDevice(IDirect3DDevice9 **ppDevice)
  132. {
  133.     return S_OK;
  134. }
  135.  
  136. // Required implementation
  137.  
  138. STDMETHODIMP_(D3DSURFACE_DESC) CDirect3DSurface9::GetDesc()
  139. {
  140.     return m_Desc;
  141. }
  142.  
  143. // Assume the entire surface is being locked.
  144. STDMETHODIMP CDirect3DSurface9::LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags)
  145. {
  146.     pLockedRect->Pitch = m_Desc.Width * 4;
  147.     pLockedRect->pBits = m_pData;
  148.     return S_OK;
  149. }
  150.  
  151. STDMETHODIMP CDirect3DSurface9::UnlockRect()
  152. {
  153.     return S_OK;
  154. }
  155.  
  156.  
  157.  
  158. IDirect3DSurface9 *GetCloneSurface(int iWidth, int iHeight)
  159. {
  160.     CDirect3DSurface9 *pSurf = new CDirect3DSurface9;
  161.  
  162.     if (!pSurf) return NULL;
  163.     if (!pSurf->Create(iWidth, iHeight))
  164.     {
  165.         delete pSurf;
  166.         return NULL;
  167.     }
  168.  
  169.     return (IDirect3DSurface9*)pSurf;
  170. }
  171.